#include "util/MD5.h"
#include "util/MD5I.h"
#include <string>

using namespace std;

//
// This class is a C++ wrapper around the C implementation contained in
// MD5I.cpp, obtained from http://sourceforge.net/projects/libmd5-rfc/.
//

kitty::util::MD5::MD5()
{
    state_ = new md5_state_s;
    md5_init(state_);
}

kitty::util::MD5::MD5(const unsigned char* data, int n)
{
    state_ = new md5_state_s;
    md5_init(state_);
    update(data, n);
    finish();
}

kitty::util::MD5::~MD5()
{
    delete state_;
}

void
kitty::util::MD5::update(const unsigned char* data, int n)
{
    md5_append(state_, data, n);
}

void
kitty::util::MD5::finish()
{
    md5_finish(state_, digest_);
    md5_init(state_);
}

void
kitty::util::MD5::digest(unsigned char* digest) const
{
    memcpy(digest, digest_, sizeof(unsigned char) * 16);
}

